package com.freemyleft.left.left_app.mian.index.work.roborder.adapter;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.freemyleft.left.zapp.ui.recycler.DataConverter;
import com.freemyleft.left.zapp.ui.recycler.MultipleFields;
import com.freemyleft.left.zapp.ui.recycler.MultipleItemEntity;


import java.util.ArrayList;

import static com.freemyleft.left.left_app.mian.index.work.roborder.adapter.RobOrderAdapter.ROB_ORDER_TYPE;

public class RobOrderConvert extends DataConverter {
    @Override
    public ArrayList<MultipleItemEntity> convert() {
        ArrayList<MultipleItemEntity> entities = new ArrayList<>();
        JSONObject object = JSONObject.parseObject(getJsonData());
        JSONArray result = object.getJSONArray("result");
        int size = result.size();
        for (int i = 0; i < size; i++) {
            JSONObject object1 = result.getJSONObject(i);
            String id = object1.getString("id");
            String name = object1.getString("name");//发布者姓名
            String head = object1.getString("head");//发布者头像
            String grade = object1.getString("grade");//年级
            String subject = object1.getString("subject");//科目
            String status = object1.getString("status");//状态
            String teacherids = object1.getString("teacherids");//已抢单老师
            String endtime = object1.getString("endtime");//结束时间
            String price = object1.getString("price");
            String hour = object1.getString("hour");
            String lon = object1.getString("long");
            String lat = object1.getString("lat");
            String addinfo = object1.getString("addinfo");
            MultipleItemEntity e = MultipleItemEntity.builder()
                    .setField(MultipleFields.ITEM_TYPE, ROB_ORDER_TYPE)
                    .setField(RobOrderAdapter.RobOrderFiles.HEAD, head)
                    .setField(RobOrderAdapter.RobOrderFiles.ID, id)
                    .setField(RobOrderAdapter.RobOrderFiles.END_TIME, endtime)
                    .setField(RobOrderAdapter.RobOrderFiles.STATUS, status)
                    .setField(RobOrderAdapter.RobOrderFiles.STUDENT_MESSAGE, name + " " + grade + " " + subject)
                    .setField(RobOrderAdapter.RobOrderFiles.LOCATION, addinfo)
                    .setField(RobOrderAdapter.RobOrderFiles.PRICE, price)
                    .build();
            entities.add(e);
        }

        return entities;
    }

}

